package com.masterclient.app.businessmodule.minemodule.point.contract;

import com.eoner.common.config.Config;
import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.managerlibrary.netsign.NetEnvManager;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.masterclient.app.businessmodule.minemodule.point.model.PointProductBean;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class PointProductsContractPresenter extends PointProductsContract.Presenter {
    @Override
    public void getPointProductsData(String page) {


        String url = NetEnvManager.BASE_SURL+"api/product/integral_list?version=" + Config.URL_VERSION;

        Observable<PointProductBean> observable = RetrofitUtil.getInstance().getPointProducts(url,page);

        Disposable disposable = toSubscribe(observable, new Consumer<PointProductBean>() {
            @Override
            public void accept(@NonNull PointProductBean bean) throws Exception {

                if("0".equals(bean.getCode())){
                    mView.showData(bean.getData());
                }else {
                    mView.loadFail(bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.loadFail("网络异常，请重试");
            }
        });
        mRxManager.add(disposable);


    }
}
